package com.kkb.controller;


import com.kkb.common.utils.ServletUtils;
import com.kkb.domain.AjaxResult;

import com.kkb.pojo.TbSysuser;
import com.kkb.pojo.complex.MenuItem;

import com.kkb.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 登录验证
 */
@Controller()
public class LoginController {

    @Autowired
    private SysUserService userService;


    @RequestMapping("/tologin")
    public String login() {

        return "login";
    }

    @RequestMapping(path = {"/index"})
    public String  showIndex(Model model) {
        //TODO 将来替换成登录用户的用户名
        String username = "admin";
        //取用户信息
        TbSysuser userInfo = userService.getUserInfo(username);
        //取用户菜单
        List<MenuItem> userMenu = userService.getUserMenu(username);
        //设置退出路径
        model.addAttribute("logout", "/logout");
        //设置用户信息
        model.addAttribute("user", userInfo);
        //设置菜单信息
        model.addAttribute("menus", userMenu);
        model.addAttribute("sideTheme", "theme-light");
        model.addAttribute("skinName", "skin-green");
        model.addAttribute("copyrightYear", "2020");

        return "index";
    }

    @RequestMapping("/system/main")
    public String showMainPage() {
        return "main_1";
    }

    // 切换主题
    @GetMapping("/system/switchSkin")
    public String switchSkin(ModelMap mmap) {
        return "skin";
    }


}
